package com.leadership.api.job;

import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.leadership.api.service.CertificateService;

/**
 * 
 * @author mohanlan
 *
 */
@Component("certificateJob")
public class CertificateJob {
    
    private static final Logger logger = LoggerFactory.getLogger(CertificateJob.class);
    
    @Autowired
    private CertificateService certificateService;
    
    /**
     * 每5分钟执行
     */
    @Scheduled(cron = "0 0/9 * * * ?")
    public void scanCerfificateRcord() {
        
        try {
            
            logger.info("#scanCerfificateRcord() - start at {}", new Date());
            
            certificateService.updateCertificate();
            
            logger.info("#scanCerfificateRcord() - finish at {}", new Date());
            
        } catch (Exception e) {
            logger.error("#scanCerfificateRcord() - occur exception=[{}]", e);
        }
        
    }
    
    /**
     * 
     */
    @Scheduled(cron = "0 0/6 * * * ?")
    public void updateOfflineCourse() {
        
        try {
            
            logger.info("#updateOfflineCourse() - start at {}", new Date());
            
            certificateService.updateOutCourse();
            
            logger.info("#updateOfflineCourse() - finish at {}", new Date());
            
        } catch (Exception e) {
            logger.error("#updateOfflineCourse() - occur exception=[{}]", e);
        }
        
    }
}
